<script type="text/javascript" src="<?=base_url()?>js/popup.js"></script>
<link href="<?=base_url()?>css/popup.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$j(function() {
	gettotalprice();
	//CLOSING POPUP	
	//Click out event!
	$j("#background-popup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$j(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	<? if($this->session->flashdata('error_product_quantity'))
	{
		?>
	centerPopup();
	        loadPopup();
			<?
	}
	?>
});
function gettotalprice() 
{
	$j.ajax({
		url: '<?=base_url()?>store/subtotal/',
		success: function(html) {
			$j('#total-price').html('$' + html);
			
		}
	})
}
function removeitem(id) {
	if (confirm('Are you sure you want to remove this item from your shopping cart?')) {
		$j.ajax({
			url: '<?=base_url()?>store/removeitem/',
			type: 'POST',
			data: ({id:id}),
			dataType: "html",
			success: function(html) {
				updatecart();
				gettotalprice();
				$j('#item-' + id).fadeOut();
			}
		})
	}
}
</script>
<div id="popup-box">
	
    <div id="popup-shopping">
    	<div class="close"><a href="javascript:disablePopup()"><img src="<?=base_url()?>img/CloseButton-Up.png" alt="Close" /></a></div>
        <div style="clear:both"></div>
        <div style="clear:both;padding-top:54px">
           <div id="content-pop" style="width:400px;margin:0 auto"><?php echo $this->session->flashdata('error_product_quantity');?></div>
        </div>
        <br/>
    </div>
</div>
<div id="background-popup"></div>
 <div id="store">
     <p><img src="<?=base_url()?>img/shopping-basket-tab.png" alt="Your shopping basket" /></p>
       <div style="margin-top:2px;min-height:400px">
                 <div class="row-title">
                    <div class="image">Product Image</div>
                 	<div class="name"><div style="padding-left:16px">Item Name</div></div>
                    <div class="qty">Quantity</div>
                   <div class="options">Product Options</div>
                    <div class="price">Item Cost / Total</div>
                 </div>
                 <form name="updateCart" method="post" action="<?=base_url()?>store/updateitems">
                 <?php foreach($cart as $item) 
				 {
					
				 	$product = $this->Product_model->identify($item['product_id']);
					$thumb = $this->Product_model->thumb_photo($product['id']);
					$attributes = $this->Product_model->get_attributes($product['id']);
					
					 $var = json_decode($item['attributes'],true);
					
				 ?>
                 <!--
                 <script type="text/javascript">
                 function addtocart(id) {
	var quantity=$j('#quantity-' + id).val();
	alert(quantity);
	if(quantity == '')
	{
		alert('Please enter a valid number for quantity');
		return false;
	}
	else
	{
		if(isNaN(quantity))
		{
			alert('Please enter a valid number for quantity');
		return false;
		}
		else
		{
			if(quantity <=0 )
			{
				alert('Please enter a valid number for quantity');
		return false;
			}
		}
	}
	var attributes = '';
	var myArray = new Array();
	<?php for($i=0;$i<count($attributes);$i++) 
	{ ?>
	 // use json javascript generator and pass value in json format(by Hieu)
	 myArray[<?=$i?>] = $j('#attribute-' + id + '<?=$i?>').val();
//myObject.attribute<?=$i?> = $j('#attribute-<?=$i?>').val();
	<?php } ?>
	attributes = JSON.stringify(myArray);
	$j.ajax({
		url: '<?=base_url()?>store/addtocart/',
		type: 'POST',
		data: ({quantity:quantity,product_id:<?=$product['id']?>,attributes:attributes}),
		dataType: "html",
		success: function(html) {
			updatecart();
			alert(html);
		}
	})
}
  </script>
  -->
<div class="row-item" id="item-<?=$item['id']?>">

                  <table cellpadding="0" cellspacing="0" border="0">
                 <tr> 
                   <td width="92" style="border: 1px solid #E5E5E5;"><div class="image"><a href="<?=base_url()?>store/product/<?=$product['id']?>"><img src="<?=base_url()?>uploads/products/<?=md5('mbb'.$product['id'])?>/thumb4/<?=$thumb['name']?>" /></a></div></td>
                  <td width="272"  style="border-top: 1px solid #E5E5E5;border-bottom: 1px solid #E5E5E5;"><div class="name"><?=$product['title']?></div></td>
                  <td width="169"  style="border-top: 1px solid #E5E5E5;border-bottom: 1px solid #E5E5E5;"><div class="qty"><table cellpadding="0" cellspacing="0" border="0"><tr><td>Quantity</td><td>&nbsp;</td><td><input style="border:1px solid #E5E5E5;height:29px;width:50px;" type="text" name="quantity-<?=$item['id']?>" id="quantity-<?=$item['id']?>" value="<?=$item['quantity']?>"  /></td>
                  <!--<td><img onclick="addtocart(<?=$item['id']?>)" src="<?=base_url()?>img/add-button2.png" alt="Add" /></td>--></tr></table></div></td>
                  <td width="232"  style="border-top: 1px solid #E5E5E5;border-bottom: 1px solid #E5E5E5;"><div class="options">
                      <?php
					   
						if($product['multiplesize'] == 1)
					   {
							 $multiple_stock = json_decode($product['size'],true);
						      ?>
						
                         <div style="margin-top:5px"><table cellpadding="0" cellspacing="0" border="0"><tr><td width="40">Size</td><td width="10">&nbsp;</td>
                         <td width="120">
                                    <select name="sizeproduct-<?=$item['id']?>" id="sizeproduct-<?=$item['id']?>" style="width:120px">
                                    
                                	<?php if($multiple_stock['XXXS']>0){?><option value="XXXS" <?php if($var['Size'] == 'XXXS') print ' selected="selected"';?> >XXXS</option><?php }?>
									<?php if($multiple_stock['XXS']>0){?><option value="XXS" <?php if($var['Size'] == 'XXS') print ' selected="selected"';?>>XXS</option><?php }?>
									<?php if($multiple_stock['XS']>0){?><option value="XS" <?php if($var['Size'] == 'XS') print ' selected="selected"';?>>XS</option><?php }?>
									<?php if($multiple_stock['S']>0){?><option value="S" <?php if($var['Size'] == 'S') print ' selected="selected"';?>>S</option><?php }?>
									<?php if($multiple_stock['M']>0){?><option value="M" <?php if($var['Size'] == 'M') print ' selected="selected"';?>>M</option><?php }?>
									<?php if($multiple_stock['L']>0){?><option value="L" <?php if($var['Size'] == 'L') print ' selected="selected"';?>>L</option><?php }?>
									<?php if($multiple_stock['XL']>0){?><option value="XL" <?php if($var['Size'] == 'XL') print ' selected="selected"';?>>XL</option><?php }?>
									<?php if($multiple_stock['XXL']>0){?><option value="XXL" <?php if($var['Size'] == 'XXL') print ' selected="selected"';?>>XXL</option><?php }?>
									<?php if($multiple_stock['3XL']>0){?><option value="3XL" <?php if($var['Size'] == '3XL') print ' selected="selected"';?>>3XL</option><?php }?>
									<?php if($multiple_stock['4XL']>0){?><option value="4XL" <?php if($var['Size'] == '4XL') print ' selected="selected"';?>>4XL</option><?php }?>
                                    <?php if($multiple_stock['5XL']>0){?><option value="5XL" <?php if($var['Size'] == '5XL') print ' selected="selected"';?>>5XL</option><?php }?>
                                    <?php if($multiple_stock['6XL']>0){?><option value="6XL" <?php if($var['Size'] == '6XL') print ' selected="selected"';?>>6XL</option><?php }?>
                                    <?php if($multiple_stock['6']>0){?><option value="6" <?php if($var['Size'] == '6') print ' selected="selected"';?>>6</option><?php }?>
                                    <?php if($multiple_stock['8']>0){?><option value="8" <?php if($var['Size'] == '8') print ' selected="selected"';?>>8</option><?php }?>
                                    <?php if($multiple_stock['10']>0){?><option value="10" <?php if($var['Size'] == '10') print ' selected="selected"';?>>10</option><?php }?>
                                    <?php if($multiple_stock['12']>0){?><option value="12" <?php if($var['Size'] == '12') print ' selected="selected"';?>>12</option><?php }?>
                                    <?php if($multiple_stock['14']>0){?><option value="14" <?php if($var['Size'] == '14') print ' selected="selected"';?>>14</option><?php }?>
                                    <?php if($multiple_stock['16']>0){?><option value="16" <?php if($var['Size'] == '16') print ' selected="selected"';?>>16</option><?php }?>
                                    <?php if($multiple_stock['18']>0){?><option value="18" <?php if($var['Size'] == '18') print ' selected="selected"';?>>18</option><?php }?>
                                    <?php if($multiple_stock['20']>0){?><option value="20" <?php if($var['Size'] == '20') print ' selected="selected"';?>>20</option><?php }?>
                                    <?php if($multiple_stock['22']>0){?><option value="22" <?php if($var['Size'] == '22') print ' selected="selected"';?>>22</option><?php }?>
                                </select></td>
                               </tr></table></div>
                              
                         <?php
					      } 
						if(count($attributes) > 0) 
					  { 
                         
						    $n = 0;
							for($i=0;$i<count($attributes);$i++) 
							{
								$values = $this->Product_model->get_attribute($attributes[$i]['id']);
							?><div style="margin-top:5px"><table cellpadding="0" cellspacing="0" border="0"><tr><td width="40"><?=$attributes[$i]['name']?></td><td width="10">&nbsp;</td>
                                <td width="120">
                                    <select name="attribute-<?=$item['id']?>-<?=$n?>" id="attribute-<?=$item['id']?>-<?=$n?>" style="width:120px">
                                    
                                	<?php 
									for($j=0;$j<count($values);$j++)
									 { 
									
									 ?>
                                    <option value="<?=$values[$j]?>" <?php if($var[$attributes[$i]['name']] == $values[$j]) print ' selected="selected"'; ?>><?=$values[$j]?></option>
                                    <?php } ?>
                                </select></td>
                               </tr></table></div>
                            <?php 
							$n++;
							}
						   
					   } 
					   else 
					   { 
					    /*
						 if($product['multiplesize'] == 1)
					     {
							$multiple_stock = json_decode($product['size'],true);
						      ?>
                         <div style="margin-top:5px"><table cellpadding="0" cellspacing="0" border="0"><tr><td width="40">Size</td><td width="10">&nbsp;</td>
                         <td width="120">
                                    <select name="sizeproduct" id="sizeproduct" style="width:120px">
                                    
                                	<?php if($multiple_stock['XXXS']>0){?><option value="XXXS" <?php if($var['Size'] == 'XXXS') print ' selected="selected"';?> >XXXS</option><?php }?>
									<?php if($multiple_stock['XXS']>0){?><option value="XXS" <?php if($var['Size'] == 'XXS') print ' selected="selected"';?>>XXS</option><?php }?>
									<?php if($multiple_stock['XS']>0){?><option value="XS" <?php if($var['Size'] == 'XS') print ' selected="selected"';?>>XS</option><?php }?>
									<?php if($multiple_stock['S']>0){?><option value="S" <?php if($var['Size'] == 'S') print ' selected="selected"';?>>S</option><?php }?>
									<?php if($multiple_stock['M']>0){?><option value="M" <?php if($var['Size'] == 'M') print ' selected="selected"';?>>M</option><?php }?>
									<?php if($multiple_stock['L']>0){?><option value="L" <?php if($var['Size'] == 'L') print ' selected="selected"';?>>L</option><?php }?>
									<?php if($multiple_stock['XL']>0){?><option value="XL" <?php if($var['Size'] == 'XL') print ' selected="selected"';?>>XL</option><?php }?>
									<?php if($multiple_stock['XXL']>0){?><option value="XXL" <?php if($var['Size'] == 'XXL') print ' selected="selected"';?>>XXL</option><?php }?>
									<?php if($multiple_stock['3XL']>0){?><option value="3XL" <?php if($var['Size'] == '3XL') print ' selected="selected"';?>>3XL</option><?php }?>
									<?php if($multiple_stock['4XL']>0){?><option value="4XL" <?php if($var['Size'] == '4XL') print ' selected="selected"';?>>4XL</option><?php }?>
                                    <?php if($multiple_stock['5XL']>0){?><option value="5XL" <?php if($var['Size'] == '5XL') print ' selected="selected"';?>>5XL</option><?php }?>
                                    <?php if($multiple_stock['6XL']>0){?><option value="6XL" <?php if($var['Size'] == '6XL') print ' selected="selected"';?>>6XL</option><?php }?>
                                    <?php if($multiple_stock['6']>0){?><option value="6" <?php if($var['Size'] == '6') print ' selected="selected"';?>>6</option><?php }?>
                                    <?php if($multiple_stock['8']>0){?><option value="8" <?php if($var['Size'] == '8') print ' selected="selected"';?>>8</option><?php }?>
                                    <?php if($multiple_stock['10']>0){?><option value="10" <?php if($var['Size'] == '10') print ' selected="selected"';?>>10</option><?php }?>
                                    <?php if($multiple_stock['12']>0){?><option value="12" <?php if($var['Size'] == '12') print ' selected="selected"';?>>12</option><?php }?>
                                    <?php if($multiple_stock['14']>0){?><option value="14" <?php if($var['Size'] == '14') print ' selected="selected"';?>>14</option><?php }?>
                                    <?php if($multiple_stock['16']>0){?><option value="16" <?php if($var['Size'] == '16') print ' selected="selected"';?>>16</option><?php }?>
                                    <?php if($multiple_stock['18']>0){?><option value="18" <?php if($var['Size'] == '18') print ' selected="selected"';?>>18</option><?php }?>
                                    <?php if($multiple_stock['20']>0){?><option value="20" <?php if($var['Size'] == '20') print ' selected="selected"';?>>20</option><?php }?>
                                    <?php if($multiple_stock['22']>0){?><option value="22" <?php if($var['Size'] == '22') print ' selected="selected"';?>>22</option><?php }?>
                                </select></td>
                               </tr></table></div>
                         <?php
					      }
						  else
						  {
							?>
                            <span><?=$product['short_desc']?></span>
                            
                            <?php 
						  }*/
					   } 
					   
					   ?>     
                    </div></td>
                    <td width="123" style="border: 1px solid #E5E5E5;"><div class="price">
                    	$<?=money_format('%i',$item['price'])?></div><div style="width:97px;color:#666;font-size:13px;text-align:center;margin:0 auto"><a style="color:#666;" href="javascript:removeitem(<?=$item['id']?>)" title="Remove this item from your shopping cart"><img src="<?=base_url()?>img/DeleteButton.jpg" alt="Delete" /></a></div></td>
                   </tr>
                   </table>
                    </div>
                 <?php 
				 } ?>            
                 </form>              
            </div>
            <div class="total">
            	<dl style="color: #027D5C;"><dt style="font-size:22px;margin-top:6px">Total Price<p  style="font-size:13px;">Prices Listed are Inc GST</p></dt>
                	<dd><div id="total-price" style="color:#fff;width:169px;height:46px;padding-top:8px;text-align:center;background:url(<?=base_url()?>img/greenBG.jpg) no-repeat"></div></dd>
                </dl>
            </div>
            <div id="product-buttons" style="width:314px;float:right">
                    <table cellpadding="0" cellspacing="0" border="0" width="314">
                      <tr>  
                       <td><a href="<?=base_url()?>"><img src="<?=base_url()?>img/KeepShopping.jpg" alt="Keep Shoppping" /></a></td>
                
                       <td><a href="javascript:document.updateCart.submit()"><img src="<?=base_url()?>img/UpdateBasket.jpg" alt="Update Basket" /></a></td>
                       <td><a href="<?=base_url()?>store/checkout"><img src="<?=base_url()?>img/Checkout.jpg" alt="Checkout" /></a></td>
                      </tr>
                     </table>
                  </div>  
           <div style="clear:both"></div>
     </div>